<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<title>This tests that querySelector, querySelectorAll and matchesSelector (webkitMatchesSelector) work with elements that are not in a document yet.</title>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
</head>
<body>
<script>
setup({ single_test: true });

var root = document.createElement('div');
var correctNode = document.createElement('div');
correctNode.setAttribute("id", "testId");
root.appendChild(correctNode);
var noChild = document.createElement('div');

assert_equals(root.querySelector('div'), correctNode);
assert_equals(root.querySelector('#testId'), correctNode);

assert_equals(root.querySelectorAll('div').length, 1);
assert_equals(root.querySelectorAll('div').item(0), correctNode);
assert_equals(root.querySelectorAll('#testId').length, 1);
assert_equals(root.querySelectorAll('#testId').item(0), correctNode);

assert_equals(noChild.querySelector('div'), null);
assert_equals(noChild.querySelectorAll('div').length, 0);

assert_true(correctNode.webkitMatchesSelector('div'));
assert_true(correctNode.webkitMatchesSelector('#testId'));
done();
</script>
</body>
</html>
